<template>
	<view>
		<view v-if="off_accident == 1" class="order-detail">
			<view class="my-list-detail">
				<view class="ml-item">
					<view style="font-size: 40rpx;font-weight: 700;margin-bottom: 20rpx;">异常报备详情</view>
					<view>
						<view style="font-size: 35rpx;font-weight: 700;margin-bottom: 20rpx;">报备名称：<text
								style="font-size: 35rpx;font-weight: 700;color: red;">{{data.accidentName}}</text>
						</view>
					</view>
					<view>
						<view style="font-size: 35rpx;font-weight: 700;margin-bottom: 20rpx;">报备内容： <text
								style="font-size: 35rpx;font-weight: 700;">{{data.accidentContent}}</text></view>
					</view>
					<view>
						<view style="font-size: 35rpx;font-weight: 700;margin-bottom: 20rpx;">报备内容：</view>
						<u-input v-model="accidentNote" type="textarea" border="true" height="80" auto-height="true" />

					</view>
					<view>
						<view style="font-size: 35rpx;font-weight: 700;margin-bottom: 20rpx;">报备图片：</view>
						<view class="r-con">
							<u-upload ref="qtjzUf" width="200" height="200" max-count="1" :file-list="list"
								:action="ufAction" :header="ufHeader" :name="'file'"
								:form-data="{ftype: 'BACK_SET_DATA_IMG',}" :max-size="1024*1024*30"></u-upload>
						</view>
					</view>
					<u-button type="primary" @click="btn_submit">提交报备</u-button>

				</view>
			</view>
		</view>

		<view v-else class="order-detail">
			<view class="my-list-detail">
				<view style="text-align: center;" class="ml-item">
					<text style="font-weight: 700;width: 100%;">点击下列即可拨打电话</text>
				</view>
				<view @click="phone1" class="ml-item">
					<view v-if="data.noticeTravel == 1">旅行社电话：{{phone.mobile}}</view>
				</view>
				<view @click="phone2" v-if="data.noticeService == 1" class="ml-item">
					<view>调度电话：{{phone.dispatchMobile}}</view>
				</view>
			</view>
		</view>
		<MyModel v-if="shareMd.show" :title="'异常报备分享'" :btnList="shareMd.btnList" @btnClick="shareMdClick">
			<template #mm-cont>
				<view>{{shareMd.content}}</view>
			</template>
		</MyModel>
	</view>
</template>

<script>
		import MyModel from '@/components/my-model/my-model.vue';
	export default {
components: {
			
			MyModel
		},
		data() {
			return {
				off_accident: 1,
				// 文件上传地址
				ufAction: this.C.upfileUrl,
				// 文件上传请求头信息
				ufHeader: {
					'token': uni.getStorageSync(this.C.uuid)
				},
				orderNum: '',
				id: '',
				data: {},
				accidentNote: "",
				list: [],
				phone: "",
				// 分享弹框
				shareMd: {
					show: false,
					// 弹框内容
					content: '',
					btnList: [{
							text: '取消',
							sty: {
								'background': '#ffffff',
								'color': '#00c3ce',
								'padding': '0 20rpx !important',
								'margin': '0 20rpx'
							}
						},
						{
							text: '分享',
							openType: 'share',
							sty: {
								'background': '#00c3ce',
								'color': '#ffffff',
								'padding': '0 20rpx !important',
								'margin': '0 20rpx'
							}
						},
					]
				},
			}
		},
		onLoad(e) {
			let that = this
			that.orderNum = e.orderNum
			that.id = e.id
			uni.getStorage({
				key: 'storage_accidentNotice',
				success: function(res) {
					that.data = res.data
					console.log(res.data);
				}
			});
			uni.getStorage({
				key: 'phone',
				success: function(res) {
					that.phone = res.data
				}
			});

		},
		methods: {

			phone1() {
				uni.makePhoneCall({
					phoneNumber: this.phone.mobile
				});
			},
			phone2() {
				uni.makePhoneCall({
					phoneNumber: this.phone.dispatchMobile
				});
			},
			// 分享弹框点击事件
			shareMdClick(index) {
				const that = this,
					U = that.U,
					md = that.shareMd;
				console.log('点击的index', index);
			
				if (index === 0) {
					md.show = false;
					if (that.data.noticeService == 1 || that.data.noticeTravel == 1) {
						that.off_accident = 2
					} else {
						uni.navigateBack({
							delta: 1
						});
					}
				} else if (index === 1) {
					console.log('点击了分享');
			
					setTimeout(function() {
						md.show = false;
						if (that.data.noticeService == 1 || that.data.noticeTravel == 1) {
							that.off_accident = 2
						} else {
							uni.navigateBack({
								delta: 1
							});
						}
					}, 800);
				}
			},
			initMpShare(o) {
				const that = this;
			
				// 小程序-分享
				that.$u.mpShare = {
					// eg：已接杜伟5人出发预计16.30分在芳华酒店完团！
					title: o.title || '分享订单标题',
					// 默认为当前页面路径，一般无需修改，QQ小程序不支持
					path: '/order-man/order-detail/order-detail?orderNum=' + o.orderNum+'&id='+o.id,
					// 分享图标，路径可以是本地文件路径、代码包文件路径或者网络图片路径。
					// 支持PNG及JPG，默认为当前页面的截图
					// imageUrl: `${that.C.staticNetUrl}/share-order-img.png`
				}
			},
			// 打开/关闭-分享弹框
			setShareMd(e) {
				const that = this,
					md = that.shareMd,
					ps = e.ps;
			
				if (e.show) { // 打开弹框
					
					that.initMpShare({
						title: '【异常报备】'+ that.data.accidentContent,
						orderNum: ps.orderNum,
						id: ps.id,
					});
			// 		that.$u.api.getOrderShareTitle(ps).then(res => {
			
			
			// 			// 存在标题才初始化
			// 			if (res.data) that.initMpShare({
			// 				title: res.data,
			// 				orderNum: ps.orderNum,
			// 				id: ps.id,
			// 			});
			// 		});
			
				
						md.content = '异常报备成功，立即去分享吧！';
				
			
					// 打开弹框
					md.show = true;
				} else { // 关闭弹框
					md.show = false;
				}
			},
			btn_submit() {
				let that = this

				let uflist = that.$refs.qtjzUf.lists;
				console.log(uflist)
				if (uflist.length > 0) {
					// let num = uflist[0].response.data[0]
					// var images= uflist[0].response.files[num].val
					var images = uflist[0].response.data.file.url
				} else {
					var images = ''
				}
				console.log(images)
				let ps = {
					accidentId: that.data.id,
					id: that.id,
					accidentInfo: {
						accidentContent: that.data.accidentContent,
						accidentName: that.data.accidentName,
						accidentNote: that.accidentNote,
						accidentUrl: images,
					}

				}

				// if (!that.data.needNote && !ps.accidentInfo.accidentNote) {
				// 	return uni.showToast({
				// 		title: '请填写报备内容',
				// 		duration: 2000,
				// 		icon: 'none',
				// 	});
				// }
				console.log(that.data.needPicture,'111',that.data)
				if (that.data.needPicture && !images) {
					return uni.showToast({
						title: '请上传报备图片',
						duration: 2000,
						icon: 'none',
					});
				}

				that.$u.api.accidentNotice(ps).then(res => {

					if (res.code == 1) {
						// 打开分享弹框
						that.setShareMd({
							show: true,
							ps: {
								operType: 0,
								orderNum: that.orderNum,
								id: that.id,
								arrivePlace: 'START_PLACE',
							}
						});
						


					}else{
						return uni.showToast({
							title:'【接口错误】'+ res.msg,
							duration: 2000,
							icon: 'none',
						});
					}

				});


			}
		}
	}
</script>
<style lang="less">
	.order-detail {
		/* #ifdef MP-WEIXIN */
		height: 100vh;
		overflow-y: auto;
		/* #endif */

		background: #efefef;
		padding: 20rpx;
	}
</style>